package es.agroservicio.Agroservicio.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import es.agroservicio.Agroservicio.domain.Product;
import es.agroservicio.Agroservicio.repository.ProductDAO;
import es.agroservicio.Agroservicio.service.ProductsManager;

@Controller
public class ProductController {

	@Autowired
	private ProductsManager productManager;
	@Autowired
	private ProductDAO productDao;

	protected final Log logger = LogFactory.getLog(getClass());

	@RequestMapping(value = "/products.html")
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		return new ModelAndView("products");
	}

	@RequestMapping(value = "/getProduct.html", method = RequestMethod.GET)
	public @ResponseBody
	Product getProduct(@RequestParam("id") String id) throws Exception {

		return this.productManager.getProductById(id);
	}

	@RequestMapping(value = "/getProductsIdNames.html", method = RequestMethod.GET)
	public @ResponseBody
	Map<String, String> getProductsIdNames() throws Exception {

		return this.productManager.getProductsIdName();
	}

}
